package com.usercontrol;

import com.dao.UserDao;
import org.apache.struts2.interceptor.RequestAware;

import javax.naming.NamingException;
import java.sql.SQLException;
import java.util.Map;

/**
 * @author :wn
 * @program : 学生信息管理系统
 * @descript : 登录
 * @create :2020-11-13 22:32
 */

public class LogonAction implements RequestAware {
    private String name;
    private String password;
    private String determinepassword;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDeterminepassword() {
        return determinepassword;
    }

    public void setDeterminepassword(String determinepassword) {
        this.determinepassword = determinepassword;
    }

    public String logon() throws SQLException, NamingException {
        boolean whetherToRegister = false;
        whetherToRegister = new UserDao().addUser(name, password, determinepassword);
        if (whetherToRegister) {
            String information = "恭喜注册成功！！";
            request.put("error", information);
            return "success";
        } else {
            String information = "注册失败！！";
            request.put("error", information);
            return "error";
        }

    }
    Map<String, Object> request;
    @Override
    public void setRequest(Map<String, Object> map) {
        this.request = map;
    }
}
